home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 2 / Amiga Tools 2.iso / grafik / bildanzeiger / superview-lib_dev / example_svoperators / extractgrayscales / sp_buffersubs.c < prev    next >
C/C++ Source or Header  |  1995-03-09  |  4KB  |  117 lines

  1.  /* SD_BufferSubs.c
  2.     - Functions for handling external drivers -
  3.     (c) 1990-94 by Andreas R. Kleinert
  4.     Last changes : 30.10.1994
  5.  */
  6.  
  7. #include "svoperator.h"
  8.  
  9. #include <proto/superview.h>
  10.  
  11.  
  12. /* *************************************************** */
  13. /* *                             * */
  14. /* * SVP_SVP_DoOperation :                           * */
  15. /* *                             * */
  16. /* *************************************************** */
  17.  
  18. void SVLI_256ToGrayScales(struct SV_GfxBuffer *gfxb);
  19. void SVLI_24ToGrayScales(UBYTE *source, UBYTE *dest, UBYTE *color, ULONG width, ULONG height);
  20.  
  21. ULONG __saveds __asm SVP_DoOperation(  register __a1 struct SVOperatorHandle  *SVOperatorHandle_a1,
  22.                                        register __a2 struct SV_GfxBuffer      *source,
  23.                                        register __a3 struct SV_GfxBuffer     **dest,
  24.                                        register __d1 APTR                      future)
  25. {
  26.  struct SVOperatorHandle *SVOperatorHandle = SVOperatorHandle_a1;
  27.  ULONG retval = SVERR_NO_ERROR;
  28.  
  29.  struct SV_GfxBuffer *newsource;
  30.  
  31.  if( (!source) || (!dest) || (!SVOperatorHandle) ) return(SVERR_ILLEGAL_ACCESS);
  32.  
  33.  SVOperatorHandle->ah_ramhandle = SVSUP_GetMemList();
  34.  if(!SVOperatorHandle->ah_ramhandle) return(SVERR_NO_MEMORY);
  35.  
  36.  if(source->svgfx_BufferType > SVGFX_BUFFERTYPE_ONEPLANE) return(SVERR_ACTION_NOT_SUPPORTED);
  37.  
  38.  if(source->svgfx_BufferType != SVGFX_BUFFERTYPE_ONEPLANE)
  39.   {
  40.    if(source->svgfx_BufferType == SVGFX_BUFFERTYPE_BITPLANE)
  41.     {
  42.      retval = SVSUP_BitPlaneToOnePlane8(source, &newsource);
  43.  
  44.      if(newsource)
  45.       {
  46.        SVSUP_AddMemEntry(SVOperatorHandle->ah_ramhandle, newsource);
  47.  
  48.        if((newsource)->svgfx_Buffer) SVSUP_AddMemEntry(SVOperatorHandle->ah_ramhandle, (newsource)->svgfx_Buffer);
  49.  
  50.       }else retval = SVERR_NO_MEMORY;
  51.  
  52.     }else retval = SVERR_UNKNOWN_PARAMETERS;
  53.  
  54.   }else newsource = source;
  55.  
  56.  if(retval) return(retval);
  57.  
  58.  *dest = SVSUP_AllocMemEntry(SVOperatorHandle->ah_ramhandle, sizeof(struct SV_GfxBuffer), MEMF_CLEAR|MEMF_PUBLIC);
  59.  if(*dest)
  60.   {
  61.    CopyMem(newsource, *dest, sizeof(struct SV_GfxBuffer));
  62.  
  63.    if(source->svgfx_ColorDepth == 24)
  64.     {
  65.      (*dest)->svgfx_BufferSize = source->svgfx_Width * source->svgfx_Height;
  66.      (*dest)->svgfx_ColorDepth = 8;
  67.      (*dest)->svgfx_PixelBits  = 8;
  68.     }
  69.  
  70.    if((*dest)->svgfx_Buffer = SVSUP_AllocMemEntry(SVOperatorHandle->ah_ramhandle, (*dest)->svgfx_BufferSize, MEMF_CLEAR|MEMF_PUBLIC))
  71.     {
  72.      CopyMem(newsource->svgfx_Buffer, (*dest)->svgfx_Buffer, (*dest)->svgfx_BufferSize);
  73.  
  74.      if(source->svgfx_ColorDepth == 24) SVLI_24ToGrayScales(source->svgfx_Buffer, (*dest)->svgfx_Buffer, (*dest)->svgfx_Colors, source->svgfx_Width, source->svgfx_Height);
  75.       else                              SVLI_256ToGrayScales(*dest);
  76.     }else
  77.     {
  78.      *dest = N;
  79.      retval = SVERR_NO_MEMORY;
  80.     }
  81.  
  82.   }else retval = SVERR_NO_MEMORY;
  83.  
  84.  return(retval);
  85. }
  86.  
  87. void SVLI_256ToGrayScales(struct SV_GfxBuffer *gfxb)
  88. {
  89.  ULONG i, colors, grey;
  90.  
  91.  colors = ColorAcc(gfxb->svgfx_ColorDepth);
  92.  
  93.  for(i=0; i<colors; i++)
  94.   {
  95.    grey = (gfxb->svgfx_Colors[i][0] * 30 + gfxb->svgfx_Colors[i][1] * 59 + gfxb->svgfx_Colors[i][2] * 11) / 100;
  96.  
  97.    gfxb->svgfx_Colors[i][0] = (gfxb->svgfx_Colors[i][1] = (gfxb->svgfx_Colors[i][2] = (UBYTE) grey) );
  98.   }
  99. }
  100.  
  101. void SVLI_24ToGrayScales(UBYTE *source, UBYTE *dest, UBYTE *color, ULONG width, ULONG height)
  102. {
  103.  ULONG i, j;
  104.  
  105.  for(i=0; i<255; i++)
  106.   {
  107.    *color++ = i;
  108.    *color++ = i;
  109.    *color++ = i;
  110.   }
  111.  
  112.  for(i=0; i<height; i++)
  113.   {
  114.    for(j=0; j<width; j++) *dest++ = ( (*source++ * 30) + (*source++ * 59) + (*source++ * 11) ) / 100;
  115.   }
  116. }
  117.